//
//  ReTableViewCell2.m
//  海角音乐
//
//  Created by dllo on 15/8/7.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "ReTableViewCell2.h"

@implementation ReTableViewCell2

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        [self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        CGFloat X = SCREEN_WIDTH*0.0266666667; // 10
        CGFloat width = SCREEN_WIDTH*0.2933333333; // 110
        
        _pic_url1 = [[UIImageView alloc] initWithFrame:CGRectMake(X, X, width, width)];
        _pic_url1.userInteractionEnabled = YES;
        _pic_url1.layer.masksToBounds = YES;
        _pic_url1.layer.cornerRadius = 0.06*width;
        
        _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button1 addTarget:self action:@selector(ButtonAct:) forControlEvents:UIControlEventTouchUpInside];
        _button1.frame = _pic_url1.frame;
        _button1.tag = 501;
        _button1.layer.masksToBounds = YES;
        _button1.layer.cornerRadius = width*0.06;
        [self addSubview:_button1];
        
        
        CGFloat pic_X = SCREEN_WIDTH*0.3466666667; // 130
        
        _pic_url2 = [[UIImageView alloc] initWithFrame:CGRectMake(pic_X, X, width, width)];
        _pic_url2.userInteractionEnabled = YES;
        
        _pic_url2.layer.masksToBounds = YES;
        _pic_url2.layer.cornerRadius = 0.06*width;
        
        _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button2 addTarget:self action:@selector(ButtonAct:) forControlEvents:UIControlEventTouchUpInside];
        _button2.frame = _pic_url2.frame;
        _button2.tag = 502;
        _button2.layer.masksToBounds = YES;
        _button2.layer.cornerRadius = width*0.06;
        [self addSubview:_button2];
        
        
        CGFloat pic_XXX = SCREEN_WIDTH*0.6666666667; // 250
        _pic_url3 = [[UIImageView alloc] initWithFrame:CGRectMake(pic_XXX, X, width, width)];
        _pic_url3.userInteractionEnabled = YES;
        
        _pic_url3.layer.masksToBounds = YES;
        _pic_url3.layer.cornerRadius = 0.06*width;
        
        _button3 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button3 addTarget:self action:@selector(ButtonAct:) forControlEvents:UIControlEventTouchUpInside];
        _button3.frame = _pic_url3.frame;
        _button3.tag = 503;
        _button3.layer.masksToBounds = YES;
        _button3.layer.cornerRadius = width*0.06;
        
        [self addSubview:_button3];
        
        [self.contentView addSubview:_pic_url1];
        [self.contentView addSubview:_pic_url2];
        [self.contentView addSubview:_pic_url3];
        
        
        CGFloat name_YY = SCREEN_WIDTH*0.32; // 120
        CGFloat name_height = 40*ADJUSTWIDTH; // 40
        
        _name1 = [[UILabel alloc] initWithFrame:CGRectMake(X, name_YY, width, name_height)];
        _name1.font = [UIFont boldSystemFontOfSize:13];
        _name1.numberOfLines = 0;
        _name1.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_name1];
        
        _name2 = [[UILabel alloc] initWithFrame:CGRectMake(pic_X, name_YY, width, name_height)];
        _name2.font = [UIFont boldSystemFontOfSize:13];
        _name2.numberOfLines = 0;
        _name2.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_name2];
        
        _name3 = [[UILabel alloc] initWithFrame:CGRectMake(pic_XXX, name_YY, width, name_height)];
        _name3.font = [UIFont boldSystemFontOfSize:13];
        _name3.numberOfLines = 0;
        _name3.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_name3];
        
        
        [_name1 release];
        [_name2 release];
        [_name3 release];
        [_pic_url1 release];
        [_pic_url2 release];
        [_pic_url3 release];
        
    }
    
    return self;
}



// button 点击方法
- (void)ButtonAct:(UIButton *)sender
{
    
    
    NSInteger senderTag = sender.tag-501;
    
    NSDictionary *dic = [self.detailArr objectAtIndex:senderTag];
    
    RecommedModel *recommedModel = [[RecommedModel alloc] init];
    
    [recommedModel setValuesForKeysWithDictionary:dic];    
    
    [self.delegate gotoHotListViewControllerWithTag:recommedModel];   
    
}



- (void)getHotMusicDataArr:(NSArray *)dataArr
{
    
    self.detailArr = dataArr;
    
    NSDictionary *dic1 = [dataArr objectAtIndex:0];
    NSDictionary *dic2 = [dataArr objectAtIndex:1];
    
    // 数据大于2 的时候
    if (dataArr.count > 2) {
        
        NSDictionary *dic3 = [dataArr objectAtIndex:2];
        
        [_pic_url3 sd_setImageWithURL:[NSURL URLWithString:[dic3 objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"grid_default.png"]];
        
        [_button3 setBackgroundImage:_pic_url3.image forState:UIControlStateNormal];
        _name3.text = [dic3 objectForKey:@"name"];
    } else {
        
        _pic_url3.hidden = YES;
        _name3.hidden = YES;
    }
    
    [_pic_url1 sd_setImageWithURL:[NSURL URLWithString:[dic1 objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"grid_default.png"]];
    [_pic_url2 sd_setImageWithURL:[NSURL URLWithString:[dic2 objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"grid_default.png"]];
    
    [_button1 setBackgroundImage:_pic_url1.image forState:UIControlStateNormal];
    [_button2 setBackgroundImage:_pic_url2.image forState:UIControlStateNormal];
    
    _name1.text = [dic1 objectForKey:@"name"];
    _name2.text = [dic2 objectForKey:@"name"];
    
    
    
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
